/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.kth.lwr.jeat.samples.onsitetreatment.producers;

import se.kth.lwr.jeat.samples.onsitetreatment.SimpleProduction;
import javax.measure.quantity.VolumetricDensity;
import javax.measure.unit.NonSI;
import javax.measure.unit.SI;
import javax.measure.unit.Unit;
import org.jscience.physics.amount.Amount;
import se.kth.lwr.jeat.core.*;
import se.kth.lwr.jeat.utils.*;



/**
 *
 * @author davidev
 */
public class GravelAndSandExtraction extends SimpleProduction {

    private GravelAndSandExtraction(ProductionSupport support) {
        super(support);

    }

    private static GravelAndSandExtraction getInstance(String name) {
        DefaultAmountConverter manager = new DefaultAmountConverter(SI.CUBIC_METRE);
        manager.setAcceptFunction(SI.KILOGRAM, new AmountFunction().divide(densityGravel));
        return new GravelAndSandExtraction(new ProductionSupport(name, gravelAndSandInventoryDataSource, manager));

    }

    public static GravelAndSandExtraction getGravelInstance() {

        return getInstance("gravel");
    }

    public static GravelAndSandExtraction getSandInstance() {

        return getInstance("sand");


    }

    public Activity getProduction(String name, String desc, AmountVolume volume, AmountDataSource duration, AmountDataSource pe) {
        AmountFunction function = volume.getVolume().divide(duration).divide(pe);
        return super.getProductionSupport().getProduction(name, desc, function);
    }
//Data sources
    /**
     * Desity of gravel and sand products
     * <p/>
     * Value: 2.200
     * <p/>
     * Unit: kg/L
     */
    public static final AmountDataSource densityGravel = new AmountDataSource<>(
            "densityGravel",
            "Desity of gravel and sand products",
            Amount.valueOf(2.200, ((Unit<VolumetricDensity>) SI.KILOGRAM.divide(NonSI.LITER))));
    /**
     *
     * Resource use during extraction of natural sand and gravel material
     *
     */
    public static final InventoryDataSource gravelAndSandInventoryDataSource = new InventoryDataSource("GravelAndSandProductionEmissions",
            "Resource use during extraction of natural sand and gravel material",
            new Inventoriable() {

                //OBS - ser ut att vara fel värden i VEVA!!!!
                @Override
                public Inventory getInventory() {
                    Inventory retval = Inventory.emptyInventory();
                    retval.addEnergyUse(EnergyCategory.ELECTRICAL, Amount.valueOf(1.16, Unit.valueOf("MJ/m*m*m")));
                    retval.addEnergyUse(EnergyCategory.FOSSIL, Amount.valueOf(0.44, Unit.valueOf("MJ/m*m*m")));
                    retval.addResourceUse(ResourceCategory.GRAVEL, Amount.valueOf(1, Unit.ONE));
                    return retval;
                }
            });
}
